/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.component.tree.node;

import javax.swing.Icon;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.component.tree
 * @date 15/02/2014 - 08:42:13
 */
public class IconNode extends DefaultMutableTreeNode {
	
	private static final long serialVersionUID = 2570676774855867750L;
	
	protected Icon icon;
	
	protected String iconName;
	
	/**
	 * 
	 */
	public IconNode() {
	
		this(null);
	}
	
	/**
	 * @param userObject
	 */
	public IconNode(final Object userObject) {
	
		this(userObject, true, null);
	}
	
	/**
	 * @param userObject
	 * @param allowsChildren
	 * @param icon
	 */
	public IconNode(final Object userObject, final boolean allowsChildren, final Icon icon) {
	
		super(userObject, allowsChildren);
		
		this.icon = icon;
	}
	
	/**
	 * @return icon
	 */
	public Icon getIcon() {
	
		return icon;
	}
	
	/**
	 * @return iconName
	 */
	public String getIconName() {
	
		//
		if(iconName != null) {
			
			return iconName;
			
		}else {
			
			final String value = userObject.toString();
			
			int index = value.lastIndexOf(".");
			
			//
			if(index != -1) {
				
				return value.substring(++index);
				
			}else {
				
				return null;
			}
		}
	}
	
	/**
	 * @param icon
	 */
	public void setIcon(final Icon icon) {
	
		this.icon = icon;
	}
	
	/**
	 * @param iconName
	 */
	public void setIconName(final String iconName) {
	
		this.iconName = iconName;
	}
}
